import request from "@/api";
import { BaseRet, PageQuery, PageRet } from "../../response";

class RoleApi {
  /**
   * 查询
   * @param data
   * @returns
   */
  static async query(data: RoleQuery): Promise<PageRet<Role>> {
    return await request({
      url: "/sysRole/index",
      method: "post",
      data: data,
    });
  }

  /**
   * 新增
   * @param data
   * @returns
   */
  static async create(data: Role): Promise<BaseRet> {
    return await request({
      url: "/sysRole/create",
      method: "post",
      data: data,
    });
  }

  /**
   * 更新
   * @param data
   * @returns
   */
  static async update(data: Role): Promise<BaseRet> {
    return await request({
      url: "/sysRole/update",
      method: "put",
      data: data,
    });
  }

  /**
   * 删除
   * @param id
   * @returns
   */
  static async delete(id: string): Promise<BaseRet> {
    return await request({
      url: `/sysRole/delete/${id}`,
      method: "delete",
    });
  }
}

export default RoleApi;

export interface Role {
  id?: string;
  roleName?: string;
  isAdmin?: boolean;
  isEnabled?: boolean;
}

export interface RoleQuery extends PageQuery {
  searchString: string;
}
